<?
class Biz_Schedule{
	//检查球队ID和比赛ID
	function checkTeamGame($teamid,$gamecode){
		$schedule = new Data_Schedule();
		$list = $schedule->checkTeamGame($teamid,$gamecode);
		$list = $list['result'][0];
		if(!$list) return false;
		$tactics = $schedule->getScheduleTactics($teamid,$gamecode);
		return array('list'=>$list,'tactic'=>$tactics['result']);
	}
	//根据筛选条件获取赛程
	function getSchedule($filter,$order = 'date ASC',$limit = null){
		$cache_key	= "Schedule".serialize($filter);
		if($force === true) $data = Lib_Cache::get($cache_key);
		if(!$data){
			if(!is_array($filter) || empty($filter))return false;
			//先从赛程表中取出赛程
			$schedule = new Data_Schedule();
			$team_list = Biz_Team::getAllTeam();
			$res = $schedule->getSchedule($filter,$order,$limit);
			$day_to_cn = array(0=>'日',1=>'一',2=>'二',3=>'三',4=>'四',5=>'五',6=>'六');
			if(count($res['result']) >0){
				foreach ($res['result'] as $per){
					$per['h_team_name'] = $team_list[$per['hteamid']]['name'];
					$per['v_team_name'] = $team_list[$per['vteamid']]['name'];
					$per['h_team_url'] = Biz_Common::getURL('team',$per['hteamid']);
					$per['v_team_url'] = Biz_Common::getURL('team',$per['vteamid']);
					$per['game_url'] = Biz_Common::getURL('gameinfo',$per['gamecode'],$filter['season']);
					$per['date_format'] = strtotime($per['datetime']);
					$per['week_cn'] = $day_to_cn[date('w',$per['date_format'])];
					$data[$per['gamecode']] = $per;
				}
				Lib_Cache::set($cache_key,$data);
			}
		}
		return $data;
	}
	//获得全部比赛数据
	function getAllGameData(){
		$cache_key	= "ZC_AllGameData";
		if($force === true) $data = Lib_Cache::get($cache_key);
		if(!$data){
			$schedule = new Data_Schedule();
			$res = $schedule->getAllGameData();
			if(count($res['result']) >0){
				$data = $res['result'];
				Lib_Cache::set($cache_key,$data);
			}
		}
		return $data;
	}
	//获得全部比赛数据
	function getGameData($season,$round){
		$cache_key	= "ZC_GameData".$season."-".$round;
		if($force === true) $data = Lib_Cache::get($cache_key);
		if(!$data){
			$schedule = new Data_Schedule();
			$res = $schedule->getGameData($season,$round);
			if(count($res['result']) >0){
				foreach ($res['result'] as $per){
					$data[$per['game_id']] = $per;
				}
				Lib_Cache::set($cache_key,$data);
			}
		}
		return $data;
	}
}
?>